/**
 * 
 */
package com.roc.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.roc.dao.DaoException;
import com.roc.dao.IPagenitionDao;
import com.roc.page.BaseSearchCondition;
import com.roc.service.IPagenitionService;
import com.roc.service.ServiceException;

/**
 * @author Administrator
 *
 */
@Service
public class PagenitionServiceImpl implements IPagenitionService {
	private Logger logger = LogManager.getLogger(PagenitionServiceImpl.class);
	@Autowired
	IPagenitionDao pagenitionDao;

	/* (non-Javadoc)
	 * @see com.roc.service.IPagenitionService#findAll(com.roc.page.BaseSearchCondition, int, int)
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public List<Object> findAll(BaseSearchCondition searchCondition,
			int startRow, int maxRow) throws ServiceException {
		List<Object> searchRsList=new ArrayList<Object>();
		try {
			searchRsList=pagenitionDao.findAll(searchCondition, startRow, maxRow);
		} catch (DaoException e) {
			logger.error(e.getMessage(),e);
			throw new ServiceException(e.getMessage(),e);
		}
		return searchRsList;
	}

	/* (non-Javadoc)
	 * @see com.roc.service.IPagenitionService#count(com.roc.page.BaseSearchCondition)
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public int count(BaseSearchCondition searchCondition)
			throws ServiceException {
		int rowCount=0;
		try {
			rowCount=pagenitionDao.count(searchCondition);
		} catch (DaoException e) {
			logger.error(e.getMessage(),e);
			throw new ServiceException(e.getMessage(),e);
		}
		return rowCount;
	}
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public List<Object> findAllSQL(BaseSearchCondition searchCondition,
			int startRow, int maxRow) throws ServiceException {
		List<Object> searchRsList=new ArrayList<Object>();
		try {
			searchRsList=pagenitionDao.findAllSql(searchCondition, startRow, maxRow);
		} catch (DaoException e) {
			logger.error(e.getMessage(),e);
			throw new ServiceException(e.getMessage(),e);
		}
		return searchRsList;
	}


	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public int countSQL(BaseSearchCondition searchCondition)
			throws ServiceException {
		int rowCount=0;
		try {
			rowCount=pagenitionDao.countSql(searchCondition);
		} catch (DaoException e) {
			logger.error(e.getMessage(),e);
			throw new ServiceException(e.getMessage(),e);
		}
		return rowCount;
	}

}
